package com.fieldchain.ex.fa100.utils.chart.utils.zb;

import android.graphics.Color;

import com.fieldchain.ex.fa100.bean.kline.KDJEntity;
import com.fieldchain.ex.fa100.bean.kline.KLineBean;
import com.github.mikephil.charting.data.CombinedData;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by biyunlong
 * Email: 1225198434@qq.com
 * Data:  2018/10/16
 */
public class KDJParse {
    private int c1 = Color.parseColor("#ffcc00");
    private int c2 = Color.parseColor("#0090f7");
    private int c3 = Color.parseColor("#ffffff");
    private ZbDataParse dataParse=new ZbDataParse();

    public CombinedData getData(List<List<String>> list) {
        ArrayList<KLineBean> datas = ZbDataParse.getKlineList(list);
        KDJEntity kdjEntity = new KDJEntity(datas, 9);
        ArrayList kData = new ArrayList<>();
        ArrayList dData = new ArrayList<>();
        ArrayList jData = new ArrayList<>();
        for (int i = 0; i < kdjEntity.getD().size(); i++) {
            kData.add(new Entry(i, kdjEntity.getK().get(i)));
            dData.add(new Entry(i, kdjEntity.getD().get(i)));
            jData.add(new Entry(i, kdjEntity.getJ().get(i)));
        }


        LineData lineData = new LineData();
        LineDataSet lineSet1 = new LineDataSet(kData, "");
        LineDataSet lineSet2 = new LineDataSet(dData, "");
        LineDataSet lineSet3 = new LineDataSet(jData, "");
        initLindata(lineSet1, c1);
        initLindata(lineSet2, c2);
        initLindata(lineSet3, c3);

        lineData.addDataSet(lineSet1);
        lineData.addDataSet(lineSet2);
        lineData.addDataSet(lineSet3);

        CombinedData combinedData = new CombinedData();
        combinedData.setData(lineData);
        combinedData.setData(dataParse.getEptData(kData.size()));
        return combinedData;
    }

    public void initLindata(LineDataSet dataSet, int color) {
        dataSet.setColor(color);
        dataSet.setHighlightEnabled(false);
        dataSet.setHighlightLineWidth(1f);
        dataSet.setHighLightColor(c3);
        dataSet.setDrawValues(false);
        dataSet.setDrawCircles(false);
    }


}
